package com.zlf.demo.config;

import com.p6spy.engine.spy.appender.MessageFormattingStrategy;

import java.time.LocalDateTime;

/**
 * @ClassName P6SpyLogger
 * @Description 重写p6spy日志格式
 * @Author 张龙飞
 * @Date 2021/2/23 13:24
 */
public class P6SpyLogger implements MessageFormattingStrategy {

    public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql, String url) {
        return !"".equals(sql.trim())
                ?
                "[ " + LocalDateTime.now() + " ] --- | 花费 " + elapsed + "ms | " + category + " | 第 " + connectionId + "个连接 \n 执行语句:"
                        + sql + ";"
                : "";
    }

}
